package com.springboot.eduservice.controller;


import com.springboot.commonutils.R;
import com.springboot.eduservice.entity.Chapter.ChapterVo;
import com.springboot.eduservice.entity.EduChapter;
import com.springboot.eduservice.service.EduChapterService;
import com.springboot.eduservice.service.impl.EduChapterServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2020-05-12
 */
@RestController
@RequestMapping("/eduservice/chapter")
@CrossOrigin
public class EduChapterController {
    @Autowired
    private EduChapterServiceImpl eduChapterService;

    @ApiOperation(value = "根据课程id查询课程章节")
    @GetMapping("getchapterinfo/{courseid}")
    public R getchapterinfo(@PathVariable String courseid){
        List<ChapterVo> chapterVoList = eduChapterService.getChapterbyid(courseid);
        System.out.println(chapterVoList);
        return R.ok().data("chapterVoList",chapterVoList);
    }


    //删除章节
    @DeleteMapping("deleteinfovideo/{chapterId}")
    public R deleteinfovideo(@PathVariable String chapterId){
        eduChapterService.deleteVideo(chapterId);
        return R.ok();
    }

    //添加章节
    @PostMapping("addChapter")
    public R addChapterinfo(@RequestBody EduChapter eduChapter){
        eduChapterService.save(eduChapter);
        return R.ok();
    }

    //修改章节
    @PostMapping("updateChapter")
    public R updateChapter(@RequestBody EduChapter eduChapter){
        eduChapterService.updateById(eduChapter);
        return R.ok();
    }

    //章节id查询
    @GetMapping("selectChapterId/{chapterId}")
    public R selectChapterId(@PathVariable String chapterId){
        EduChapter chapter = eduChapterService.getById(chapterId);
        return R.ok().data("chapter",chapter);
    }


}

